package com.neuedu.his.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.his.po.Medicalrecord;
import com.neuedu.his.po.Register;
import com.neuedu.his.po.User;
import com.neuedu.his.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.neuedu.his.common.bean.ApiResult;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private RegisterService service;

    @RequestMapping("/add")
    public Boolean add(@RequestBody Register r) {
        r.setRegisttime(new Date());
        r.setVisitstate(1);
        System.out.println(r);
        return service.save(r);
    }

    @RequestMapping("/maxid")
    public ApiResult getMaxId() {
        try {
            Integer maxId = service.getMaxId();
            return ApiResult.success().data("maxId", maxId);
        } catch (Exception e) {
            return ApiResult.error("获取最大ID失败").data("error", e.getMessage());
        }
    }

    @RequestMapping("/getByUserId")  // 修改路径名
    public List<Register> getRegisterByUserId(@RequestParam Integer userid) {  // 方法名也修改
        System.out.println("getByUserId   userid="+userid);
        QueryWrapper<Register> qw = new QueryWrapper<>();
        qw.eq("userid", userid);
        return service.list(qw);
    }

    @RequestMapping("/getByDeptId")  // 修改路径名
    public List<Register> getByDeptId(@RequestParam Integer deptid) {  // 方法名也修改
        System.out.println("getByUserId   deptid="+deptid);
        QueryWrapper<Register> qw = new QueryWrapper<>();
        qw.eq("deptid", deptid);
        return service.list(qw);
    }

    @RequestMapping("/getByregisterId")  // 修改路径名
    public List<Register> getByregisterId(@RequestParam Integer registerid) {  // 方法名也修改
        System.out.println("getByregisterId   registerid="+registerid);
        QueryWrapper<Register> qw = new QueryWrapper<>();
        qw.eq("registerid", registerid);
        return service.list(qw);
    }

    @GetMapping("/getAll") // 更清晰的路径
    public List<Register> getAllRegisters() {
        return service.list();
    }



}

